import { ImplementsInterface } from "../../../Decorator/Decorator";
import { Dictionary } from "../../../Support/Share/Lib/Dictionary";
import { ISingletonAwake } from "../../Singleton/ISingletonAwake";
import { Singleton } from "../../Singleton/Singleton";
import { Entity } from "./Entity";
import { EntitySceneFactory } from "./EntitySceneFactory";
import { Scene } from "./Scene";
import { SceneType } from "./SceneType";

@ImplementsInterface(ISingletonAwake)
export class Root extends Singleton<Root> implements ISingletonAwake {

    private static _Instance: Root;
    static get Instance() {
        return this._Instance;
    }

    protected set Instance(value: Root) {
        Root._Instance = value;
    }

    private readonly allEntities = new Dictionary<number, Entity>();

    private _Scene: Scene;
    public get Scene(): Scene {
        return this._Scene;
    }
    private set Scene(value: Scene) {
        this._Scene = value;
    }

    constructor() {
        super();
    }

    public Awake() {
        this.Scene = EntitySceneFactory.CreateScene(0, SceneType.Process, "Process");
    }

    public Dispose(): void {
        this.Scene.Dispose();
    }

    public Add(entity: Entity): void {
        this.allEntities.Add(entity.InstanceId, entity);
    }

    public Remove(instanceId: number): void {
        this.allEntities.Remove(instanceId);
    }

    public Get(instanceId: number): Entity {
        let component = this.allEntities.TryGetValue(instanceId);
        return component;
    }

}